<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户风险标记记录表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="rskCstSignLog_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">

        <div class="fieldBox col_50">
            <div class="label">客户名称</div>
            <div class="field">
                <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}"
                       validate="{required:false,maxlength:60}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">合同号</div>
            <div class="field">
                <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="${prjBscInfoVO.lsCntNo}"
                       validate="{required:false,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">设备数量</div>
            <div class="field">
                <input name="prdCount" id="prdCount" type="text" class="ui-textbox" value="${prdCount}"
                       validate="{required:false,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">项目类型</div>
            <div class="field">
                <c:forEach items="${prjTypeList}" var="prjType">
                    <c:if test="${prjType.key == prjBscInfoVO.prjTypCd}">
                        <input name="prjType" id="prjType" type="text" class="ui-textbox" value="${prjType.value}"
                               validate="{required:false,maxlength:30}" readonly="readonly">
                    </c:if>
                </c:forEach>
                    <c:if test="${prjTypeList == null}">
                        <input name="prjType" id="prjType" type="text" class="ui-textbox"
                               validate="{required:false,maxlength:30}" readonly="readonly">
                    </c:if>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">事业部</div>
            <div class="field">
                <c:forEach items="${buOrgList}" var="buOrg">
                    <c:if test="${buOrg.key == prjBscInfoVO.buOrgCd}">
                        <input name="buOrg" id="buOrg" type="text" class="ui-textbox" value="${buOrg.value}"
                               validate="{required:false,maxlength:30}" readonly="readonly">
                    </c:if>
                </c:forEach>
                <c:if test="${buOrgList == null}">
                    <input name="buOrg" id="buOrg" type="text" class="ui-textbox"
                           validate="{required:false,maxlength:30}" readonly="readonly">
                </c:if>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">融资额</div>
            <div class="field">
                <input name="financingAmt" id="financingAmt" type="text" class="ui-textbox"
                       validate="{required:false,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">当前敞口</div>
            <div class="field">
                <input name="open" id="open" type="text" class="ui-textbox"
                       validate="{required:false,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">最早起租日期</div>
            <div class="field">
                <input name="earliestRtDt" id="earliestRtDt" type="text" class="ui-textbox"
                       validate="{maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">标记类型</div>
            <div class="field">
                <input name="signResType" id="signResType" placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">标记原因<%-- 1.顶名购买 2.团单拆单 3.老赖 4.诈骗 5.法律纠纷 6.他人运营 7.私下转账 8.代收代付--%></div>
            <div class="field">
                <input name="signResCd" id="signResCd" placeholder="请选择" ltype="combobox" validate="{required:true}">
                <%--<select name="signResCd" id="signResCd" data-value=""
                        validate="{required:true}">
                    <option value="" selected>请选择</option>
                    <c:forEach items="${signResCdList}" var="item">
                        <option value="${item.key }">${item.value }</option>
                    </c:forEach>
                </select>--%>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">标记时间</div>
            <div class="field">
                <input name="crtTm" id="crtTm" type="text" class="ui-textbox" value="${crtTm}"
                       validate="{required:false,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">标记人</div>
            <div class="field">
                <input name="crtUsrNm" id="crtUsrNm" type="text" class="ui-textbox" value="${currentUserName}"
                       validate="{required:true,maxlength:30}" readonly="readonly">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">备注</div>
            <div class="field">
                <textarea name="signRem" id="signRem" type="text" class="ui-textbox" cols="120" rows="7"
                          value=""
                          validate="{required:false,maxlength:255}">${rskCstSignLogVO.signRem}</textarea>
                <%--<input name="signRem" id="signRem" type="text" class="ui-textbox" value="${rskCstSignLogVO.signRem}"
                       validate="{maxlength:255}" style="height:30px; width:50px">--%>
                <%--<span class="requiredSymbol">*</span>--%>
            </div>
        </div>
    </div>
    <div class="btnsBox">
        <span id="saveRskCstSignLog_Btn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>

    <%--<input type="hidden" id="test" value="${signResCdListJson}">--%>
</form>
<script>
    function formatNumber(str) {
        return str.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }
    // 获取字符串的字节长度
    function getByteLen(str) {
        var len = 0;
        for (var i = 0; i < str.length; i++) {
            var a = str.charAt(i);
            if (a.match(/[^\x00-\xff]/ig) != null) {
                len += 2;
            } else {
                len += 1;
            }
        }
        return len;
    }

    $(function () {
        $("#signResCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#signResType").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("signResCd").setData(${signResCdListJson});
        liger.get("signResType").setData(${signResTypeListJson});

        // 判断是查看还是修改
        var flag = "${flag}";
        // 当前风险标记原因
        var signRes = "${rskCstSignLogVO.signResCd}";
        var signResType = "${rskCstSignLogVO.signResType}";
        var signResTypeNm = "${rskCstSignLogVO.signResTypeNm}";
        if (flag == 'd') {
            // 查看详情
            var signResCd = $("#signResCd");
            $("#signRem").attr("disabled", true);
            $.each(${signResCdListJson}, function (i, o) {
                if (signRes == o.key) {
                    $("#signResCd").val(o.value);
                    // $("#signResCd").text = o.value;
                    $("#signResCd").selected = true;
                }
            });
            $("#signResType").val(signResTypeNm);
            $("#signResType").selected = true;
            liger.get('signResType').setDisabled();
            liger.get('signResCd').setDisabled();
            // $("#signResCd").prop("readOnly", true);
            $("#saveRskCstSignLog_Btn").hide();
        } else if (flag == 'c') {
            // 修改
            $.each(${signResCdListJson}, function (i, o) {
                if (signRes == o.key) {
                    $("#signResCd").val(o.value);
                    // $("#signResCd").text = o.value;
                    $("#signResCd").selected = true;
                }
            });
            $("#signResType").val(signResTypeNm);
            $("#signResType").selected = true;
            if(signResType == 3){//黑名单
                liger.get('signResType').setDisabled();
                liger.get('signResCd').setDisabled();
            }
        }

        var rskCstSignLogId = "${rskCstSignLogVO.id}";//主键ID
        var cstId = "${cstId}"; // 客户ID
        $("#rskCstSignLog_form").ligerForm({
            validate: true
        });
        /*保存*/
        $("#saveRskCstSignLog_Btn").click(function (event) {
            var form = liger.get("rskCstSignLog_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var signRem = $("#signRem").val();
            var signRenLength = getByteLen(signRem);
            if (signRenLength >= 255) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_SIGNREM_LENGTH, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            if (data.signResCd == null || data.signResCd == '') {
                data["signResCd"] = signRes;
            }
            if (data.signResType == null || data.signResType == '') {
                data["signResType"] = signResType;
            }
            $.ligerDialog.hide();
            var _url;
            if (rskCstSignLogId == '') {//新增
                _url = '<%=path%>/risk/rskCstSignLog/add.do?cstId=' + cstId;
            } else {//修改
                _url = '<%=path%>/risk/rskCstSignLog/modify.do?id=' + rskCstSignLogId + '&cstId=' + cstId;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        if($("#signResType").val() == '黑名单'){
                            liger.get('signResType').setDisabled();
                            liger.get('signResCd').setDisabled();
                        }
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        setTimeout(function(){ frameElement.dialog.close(); }, 1500);
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });
</script>
</body>
</html>
